// 引入 uni-ajax 模块
import ajax from 'uni-ajax'                                    
import store from '@/store/store.js';
const config = {
	
}
const instance = ajax.create(config)   
// 创建请求实例
instance.defaults.baseURL = 'https://www.uinav.com'

instance.interceptors.request.use(config=>{
	uni.showLoading({
		title:"数据加载中"
	})
	console.log(config)
	if (config.url.indexOf('/my/') !== -1){
		config.header.Authorization = store.state.myUser.token
	}
	return config
}, error=>{
	return Promise.reject(error)
})     
// 添加请求拦截器
instance.interceptors.response.use(response=>{
	uni.hideLoading()
	if ( response.statusCode !== 200 ){
		return Promise.reject(response)
	}
	return response
}, error=>{
	uni.hideLoading()
	uni.showToast({
	  title:'数据加载失败!',
	  duration:1500,
	  icon: 'none',
	})
	return Promise.reject(error)
})    
// 添加响应拦截器
export default instance 